package routers

import (
	"toy-car/pkg/setting"
	"toy-car/routers/api/login"
	v1 "toy-car/routers/api/v1"

	"github.com/gin-gonic/gin"
)

func InitRouter() *gin.Engine {
	r := gin.New()
	r.Use(gin.Logger())

	r.Use(gin.Recovery())

	gin.SetMode(setting.RunMode)

	{
		r.POST("/api/login/account", login.DoLogin)
		r.POST("/api/logout/account", login.DoLogout)
		r.GET("/api/captcha", login.Captcha)
	}

	apiv1 := r.Group("/api/v1")
	// apiv1.Use(jwt.JWT())
	{
		apiv1.GET("/test", v1.Test)
		apiv1.GET("/currentUser", v1.UserCurrent)
		apiv1User := apiv1.Group("user")
		{
			apiv1User.POST("register", v1.UserRegister)
			apiv1User.PUT("/:id/reset", v1.UserResetPassword)         // 重置密码
			apiv1User.POST("changePassword", v1.UserChangePassword)   // 修改密码[优先级不高]
			apiv1User.GET("users", v1.UserListWithPage)               // 获取用户列表
			apiv1User.GET("/:id", v1.UserInfo)                        // 获取用户详情
			apiv1User.DELETE("/:id", v1.UserDelete)                   // 删除用户
			apiv1User.POST("/:id/authority", v1.UserAuthorityChanged) // 设置用户权限
			apiv1User.PUT("/:id", v1.UserUpdate)                      // 更新基础信息
		}

		apiv1Dept := apiv1.Group("dept")
		{
			apiv1Dept.GET("/", v1.DeptList) // 部门列表
			apiv1Dept.POST("/", v1.DeptAdd)
			apiv1Dept.GET("/:id", v1.DeptInfo)
			apiv1Dept.PUT("/:id", v1.DeptUpdate)
			apiv1Dept.DELETE("/:id", v1.DeptDelete)
		}

		apiv1PermModule := apiv1.Group("permModule") // 权限模块
		{
			apiv1PermModule.GET("/", v1.PermModuleList)
			apiv1PermModule.POST("/", v1.PermModuleAdd)
			// apiv1Dept.PUT("/:id", v1.DeptUpdate)
		}

		apiv1Perm := apiv1.Group("perm") // 权限项
		{
			apiv1Perm.GET("/", v1.PermList)
			apiv1Perm.POST("/", v1.PermAdd)
			// apiv1Dept.PUT("/:id", v1.DeptUpdate)
		}

		apiv1PermCode := apiv1.Group("permCode") // 权限编码
		{
			apiv1PermCode.GET("/", v1.PermCodeList)
			apiv1PermCode.POST("/", v1.PermCodeAdd)
			// apiv1Dept.PUT("/:id", v1.DeptUpdate)
		}

		apiv1Menu := apiv1.Group("menu")
		{
			apiv1Menu.GET("/", v1.MenuList)
			apiv1Menu.POST("/base", v1.MenuAddBase)                // 新增菜单
			apiv1Menu.PUT("/base/:id", v1.MuneUpdateBase)          // 更新菜单
			apiv1Menu.GET("/base/:id", v1.MuneBaseGetByID)         // 根据id获取菜单详情
			apiv1Menu.DELETE("/base/:id", v1.MuneBaseDelete)       // 删除菜单
			apiv1Menu.GET("/authority/:id", v1.MuneGetByAuthority) // 根据角色返回菜单

			apiv1Menu.GET("/base/tree", v1.BaseMenuTree) // 树形结构返回基础菜单
		}

		apiv1Authority := apiv1.Group("authority")
		{
			apiv1Authority.POST("/:id/menus", v1.MuneAuthorityAdd) // 根据角色返回菜单
			apiv1Authority.POST("/", v1.AuthorityAdd)              // 创建角色
			apiv1Authority.PUT("/:id", v1.AuthorityUpdate)         // 编辑角色
			apiv1Authority.GET("/", v1.GetAuthorityList)           // 获取角色列表
			apiv1Authority.GET("/:id", v1.GetAuthorityInfo)        // 获取角色列表
			apiv1Authority.DELETE("/:id", v1.AuthorityDelete)      // 获取角色列表
		}

		apiv1Api := apiv1.Group("api")
		{
			apiv1Api.POST("/", v1.ApiAdd)            // 创建api
			apiv1Api.PUT("/:id", v1.ApiUpdate)       // 编辑api
			apiv1Api.GET("/", v1.GetApiList)         // 获取api列表
			apiv1Api.GET("/:id", v1.GetApiInfo)      // 获取api列表
			apiv1Api.DELETE("/:id", v1.ApiDelete)    // 获取api列表
			apiv1Api.POST("/del", v1.MultiApiDelete) // 获取api列表
		}

		apiv1System := apiv1.Group("system")
		{

			apiv1System.GET("/", v1.GetSystemConfig)  // 获取配置文件内容
			apiv1System.POST("/", v1.SetSystemConfig) // 获取配置文件内容
		}

		apiv1Jwt := apiv1.Group("jwt")
		{
			apiv1Jwt.POST("/", v1.JsonInBlacklist) // 获取配置文件内容
		}

		apiv1Customer := apiv1.Group("customer")
		{
			apiv1Customer.POST("/", v1.CustomerAdd)         // 创建用户
			apiv1Customer.PUT("/:id", v1.CustomerUpdate)    // 更新用户
			apiv1Customer.DELETE("/:id", v1.CustomerDelete) // 删除用户
			apiv1Customer.GET("/:id", v1.CustomerGetOne)    // 获取指定用户
			apiv1Customer.GET("/", v1.CustomerGetList)      // 获取用户列表
		}

		apiv1Excel := apiv1.Group("excel")
		{
			apiv1Excel.POST("/", v1.ExcelImport)     // 获取配置文件内容
			apiv1Excel.GET("/", v1.DownloadTemplate) // 下载模板文件
		}

		apiv1File := apiv1.Group("files")
		{
			apiv1File.POST("/", v1.FileUpload)      // 整体上传文件
			apiv1File.GET("/", v1.FileListFetch)    // 获取文件列表
			apiv1File.DELETE("/:id", v1.FileDelete) // 删除一个文件
			apiv1File.POST("/breakpoint", v1.FilebreakpointUpload)
			apiv1File.POST("/search", v1.FileSearch)
			apiv1File.POST("/breakpoint/finish", v1.FilebreakpointFinish)
			apiv1File.DELETE("/breakpoint", v1.FilebreakpointDelete)
		}

		apiv1Casbin := apiv1.Group("casbin")
		{
			apiv1Casbin.POST("/", v1.CasbinUpdate)          // 获取配置文件内容
			apiv1Casbin.GET("/", v1.CasbinGetByAuthorityID) // 下载模板文件
		}

		apiv1Dictionary := apiv1.Group("dictionary")
		{
			apiv1Dictionary.POST("/", v1.DictionaryAdd)
			apiv1Dictionary.DELETE("/:id", v1.DictionaryDelete)
			apiv1Dictionary.PUT("/:id", v1.DictionaryUpdate)
			apiv1Dictionary.GET("/:id", v1.DictionaryGetByID)
			apiv1Dictionary.GET("/", v1.DictionaryGetList)
		}
		apiv1DictionaryDetail := apiv1.Group("dictionaryDetail")
		{
			apiv1DictionaryDetail.POST("/", v1.DictionaryDetailAdd)
			apiv1DictionaryDetail.DELETE("/:id", v1.DictionaryDetailDelete)
			apiv1DictionaryDetail.PUT("/:id", v1.DictionaryDetailUpdate)
			apiv1DictionaryDetail.GET("/:id", v1.DictionaryDetailGetByID)
			apiv1DictionaryDetail.GET("/", v1.DictionaryDetailGetList)
		}

		apiv1Autocode := apiv1.Group("autocode")
		{
			apiv1Autocode.POST("/package/", v1.AutocodePackageAdd)
			apiv1Autocode.GET("/package", v1.AutocodePackageList)
			apiv1Autocode.DELETE("/package/:id", v1.AutocodeDelete)

			apiv1Autocode.GET("db", v1.GetDB)             // 获取数据库
			apiv1Autocode.GET("table", v1.GetTable)       // 获取对应数据库的表
			apiv1Autocode.GET("column", v1.GetColumns)    // 表的列
			apiv1Autocode.POST("preview", v1.PreviewTemp) // 获取自动创建代码预览
		}

		apiv1Email := apiv1.Group("email")
		{
			apiv1Email.POST("/testEmail/", v1.TestEmail)
		}
	}

	return r
}
